package com.hui10.mediaplayer.base

import android.os.Bundle
import android.support.v4.app.Fragment
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import org.jetbrains.anko.AnkoLogger
import org.jetbrains.anko.runOnUiThread
import org.jetbrains.anko.toast

/**
 * Author: Created by lucus on 2019/5/23.
 * E-mail: mcphilex1989@gmail.com
 * Tel: 15652608401
 * Describer: Fragment 基类
 */
abstract class BaseFragment : Fragment(), AnkoLogger {

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        init()
    }

    override fun onCreateView(inflater: LayoutInflater, container: ViewGroup?, savedInstanceState: Bundle?): View? {
        return initView()
    }

    override fun onActivityCreated(savedInstanceState: Bundle?) {
        super.onActivityCreated(savedInstanceState)
        initListener()
        initData()
    }

    protected open fun initData() {

    }

    protected open fun initListener() {

    }

    abstract fun initView(): View?

    protected fun init() {

    }

    protected fun showT(msg: String) {
        context?.let {
            it.runOnUiThread {
                toast(msg)
            }
        }
    }

}